package com.fire.web.modules.all.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.fire.web.modules.all.constant.ErrorCodeConstants;
import com.fire.web.modules.all.entity.AjaxResult;
import com.fire.web.modules.all.entity.ReceiveAreaModel;
import com.fire.web.modules.all.mapper.ReceiveAreaMapper;
import com.fire.web.modules.all.service.IReceiveAreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 收货区域Service
 *
 * @author Matthew
 * @Date 2019-01-17 20:50
 */
@Service
public class ReceiveAreaServiceImpl extends ServiceImpl<ReceiveAreaMapper, ReceiveAreaModel> implements IReceiveAreaService {

	private static final Logger LOGGER = LoggerFactory.getLogger(ReceiveAreaServiceImpl.class);

	@Autowired
	private ReceiveAreaMapper receiveAreaMapper;

	@Override
	public ReceiveAreaModel selectOne(ReceiveAreaModel entity) {
		return receiveAreaMapper.selectOne(entity);
	}

	@Override
	public List<ReceiveAreaModel> selectList(ReceiveAreaModel model) {
		return receiveAreaMapper.selectListByModel(model);
	}

	@Override
	public Page<ReceiveAreaModel> selectPage(int currentPage, int pageSize, Wrapper<ReceiveAreaModel> wrapper) {
		return selectPage(new Page<ReceiveAreaModel>(currentPage, pageSize), wrapper);
	}

	@Override
	public Page<Map<String, Object>> selectMapsPage(int currentPage, int pageSize, Wrapper<ReceiveAreaModel> wrapper) {
		return selectMapsPage(new Page<ReceiveAreaModel>(currentPage, pageSize), wrapper);
	}

	@Override
	public AjaxResult getProvinceOpt() {
		List<Map> result = receiveAreaMapper.getProvinceOpt();
		return new AjaxResult(ErrorCodeConstants.SUCCESS, "获取成功", result, "获取成功");
	}

	@Override
	public AjaxResult getCityOrZoneOpt(String parentid) {
		List<Map> result = receiveAreaMapper.getCityOrZoneOpt(parentid);
		return new AjaxResult(ErrorCodeConstants.SUCCESS, "获取成功", result, "获取成功");
	}

	@Override
	public String getAddress(String provinceCode, String cityCode, String zonCode) {
		List result = receiveAreaMapper.getAddress(provinceCode, cityCode, zonCode);
		String address = String.join("", result);
		return address;
	}

}
